home *** CD-ROM | disk | FTP | other *** search
- Path: explorer.csc.com!not-for-mail
- From: mschlege@csc.com (Mark Schlegel)
- Newsgroups: comp.lang.rexx
- Subject: Re: Bug in OS2's SysFileSearch?
- Date: 27 Jan 1996 16:27:18 -0500
- Organization: Computer Sciences Corporation
- Distribution: world
- Message-ID: <4ee5bm$4to@explorer.csc.com>
- References: <4dmv4m$899@harbinger.cc.monash.edu.au> <3100e06e.53494d4d4f4e53@simmons.actrix.gen.nz>
- NNTP-Posting-Host: explorer.csc.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Jim Simmons (jim@simmons.actrix.gen.nz) wrote:
- : I heard a rumour that Jobst Schmalenbach <jhs@rdt.monash.edu.au> said:
- : >Hi netters,
- : >
- : > I needed to find the occurences of some string on a complete
- : >line in REXX for OS2.
- : >
- : >Here is what I did (well the most important stuff):
- : >
- : >....
- : >....
- : >/* find the files .... */
- : >...
- : >do i=1 to Files.0
- : > /* i might have mixed up the order of the parameters, i am at work
- : > not at home, so ... */
- : > rc = SysFileSearch('Path',Files.i,Lines)
- : > if rc\=0 then
- : > CleanUp rc
- : > say 'Found 'Lines.0' lines matching'
- : > do j=1 to Lines.0
- : > /* do some work here, but for the sake just display */
- : > say 'Found: 'Lines.j
- : > end
- : >end
- : >...
- : >...
- : >/* do some other stuff */
- : >
- : >However, for some crazy reason it ALWAYS found ONLY 1 matching line
- : >although there were at least 10 entries in EACH file that
- : >is Lines.0 showed only ONE entry found.
- : >HUH?
-
- You have to be careful, I don't see what you do to get
- that File. stem but remember that if you are using sysfiletree
- to get filenames to put in a stem (looks like Files.i in your prog)
- that the stem it returns is a complex set of 5 words of which
- the file path is the 5th word:
-
- filespec = 'f:\rexx\progs\*.*'
- call sysfiletree filespec,'Files','f'
-
- would populate stem -> files. with all the files in path filespec
- (note the 'f' option that tells sysfiletree to only get files and not
- dirs)
-
- but now note your usage of sysfilesearch:
-
- rc = sysfilesearch('path',files.i,Lines)
-
- note that files.i is wrong UNLESS you do this (and you used sysfiletree):
-
- do i = 1 to Files.0
- Files.i = word(Files.i, 5)
- rc = sysfilesearch('path', Files, Lines)
- if rc \= 0 then
- call Cleanup rc
- say 'found' Lines.0 'lines matching'
- do j = 1 to Lines.0
- say "found:" Lines.j
- end
- end
-
- ==============
- or to see a program I just wrote that I know works:
- ------- start ---------
-
- /* rexx */
-
- filespec = "f:\rexx\progs\cleanup.cmd"; /* just one file to test*/
- /* in real use, likely a
- wildcard ie f:\dir1\*.* */
- call sysfiletree filespec,'files','f';
- phrase = 'then'; /* <-- key phrase to search for */
-
- do i = 1 to files.0
- file = word(files.i, 5); /* only send filename to sysfilesearch*/
- rc = sysfilesearch(phrase, file, Lines, "n");
- if rc \= 0 then
- call Cleanup rc; /* whatever that does? */
- say 'found' Lines.0 'lines that match' phrase 'in file' filespec
- do j = 1 to Lines.0
- say "At line #:" Lines.j
- end
- end
-
- --------- end ------------
-
- note that files.i is in general:
-
- MM/DD/YY HH:MM size(bytes) attribute_list filename
-
- which is why you must use word(files.i, 5) to only put word #5
- which is the full filename to 'file' . I then run file in each
- iteration of sysfilesearch....or you could just put filename back
- to files.i recursively if you want:
-
- .......
- do i = 1 to files.0
- files.i = word(files.i, 5)
- rc = sysfilesearch(phrase, files.i, Lines,"n")
- if rc \= 0 then
- call Cleanup rc
- say 'Found' Lines.0 'lines that match' phrase
- do j = 1 to Lines.0
- say "Line #:" Lines.j
- end
- end
-
- =========== end
-
- also note the 'n' option in sysfilesearch, this adds a nice
- bit of info to each Lines.j ... it adds the line number of
- the match to the start of each Lines.j
-
- mark
-
-